package javase.reflection;

import com.sun.deploy.util.StringUtils;

import java.lang.reflect.Field;
import java.util.Date;

/**
 * 学习反射机制
 * @author LiShaowen
 * @date 2020/9/6 20:46
 */
public class TestReflection {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        Class c1 = Class.forName("javase.reflection.Student");
        Class c2 = Class.forName("java.lang.String");
        System.out.println(c1.hashCode());
        System.out.println(c2.hashCode());
        Class c3 = Student.class;
        Field[] declaredFields = c3.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField);
        }
        System.out.println(javase.reflection.Student.class.getClassLoader());
        System.out.println(new String().getClass().getClassLoader());

    }
}
class Student{
    private int id;
    private String name;
    private int age;

    public Student() {
    }

    public Student(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
